package cn.com.captureNetPacket.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import cn.com.captureNetPacket.model.ConfigInfo;
import cn.com.captureNetPacket.model.DeviceInfo;
import cn.com.captureNetPacket.model.ParamCondition;
import cn.com.captureNetPacket.model.WebResult;
import cn.com.captureNetPacket.service.DeviceInfoService;
import cn.com.captureNetPacket.util.RedisConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("/if/capture/device")
@Api(value = "DeviceInfoController", tags = { "DeviceInfoController" }, description = "DEVICEINFO相关")
public class DeviceInfoController {

	@Autowired
	private DeviceInfoService deviceInfoService;
	@Autowired
	private ObjectMapper mapper;
	
 

	@GetMapping("/getAll")
	@ApiOperation("查询DEVICEINFO表中所有数据")
	public Object getAllDeviceInfo() throws JsonProcessingException {
		WebResult ws = deviceInfoService.searchAll();
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}

	@GetMapping("/getAllByPaging/{currentPage}/{size}")
	@ApiOperation("分页查询DEVICEINFO表中所有数据")
	public Object getAllDeviceInfoByPaging(@PathVariable(name = "currentPage") int currentPage,
			@PathVariable(name = "size") int size) throws JsonProcessingException {
		WebResult ws = deviceInfoService.searchByPaging(currentPage, size);
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}
	@GetMapping("/getVoiceAssistant/{deviceNumber}")
	@ApiOperation("查询知识随行的结果")
	public Object getVoiceAssistant(@PathVariable(name = "deviceNumber") String deviceNumber) throws JsonProcessingException {
		WebResult ws = deviceInfoService.getVoiceAssistantService(deviceNumber);
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}
	
	@PostMapping("/addDeviceInfo")
	@ApiOperation("添加数据到DEVICEINFO表")
	public Object addDeviceInfo(@RequestBody DeviceInfo deviceInfo) throws JsonProcessingException {
		log.debug("---上送参数为:{}-----",deviceInfo);
		WebResult ws = deviceInfoService.create(deviceInfo);
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}

	
	@DeleteMapping("/removeDeviceInfo")
	@ApiOperation("根据id删除DEVICEINFO表中数据")
	public Object removeDeviceInfo(@RequestBody DeviceInfo deviceInfo) throws JsonProcessingException {
		log.debug("---上送参数为:{}-----",deviceInfo);
		WebResult ws = deviceInfoService.remove(deviceInfo);
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}
	
	@PatchMapping("/modifyDeviceInfo")
	@ApiOperation("根据id修改DEVICEINFO表中数据")
	public Object modifyDeviceInfo(@RequestBody DeviceInfo deviceInfo) throws JsonProcessingException {
		log.debug("---上送参数为:{}-----",deviceInfo);
		WebResult ws = deviceInfoService.modify(deviceInfo);
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}
	
	@PostMapping("/getDeviceInfoByConditionAndPaging")
	@ApiOperation("分页+条件查询DEVICEINFO表中数据")
	public Object getDeviceInfoByConditionAndPaging(@RequestBody ParamCondition<DeviceInfo> paramCondition)
			throws JsonProcessingException {
		log.debug("---上送参数为:{}-----", mapper.writeValueAsString(paramCondition));
		WebResult ws = deviceInfoService.searchByCondition(paramCondition.getCurrentPage(), paramCondition.getSize(),
				paramCondition);
		log.debug("---返回数据:---->{}", mapper.writeValueAsString(ws));
		return ws;
	}

}
